package com.cskaoyan.service.impl;

import com.cskaoyan.mapper.BrandMapper;
import com.cskaoyan.model.Address;
import com.cskaoyan.model.Brand;
import com.cskaoyan.model.bo.BaseParamBO;
import com.cskaoyan.model.vo.AddressDataVO;
import com.cskaoyan.model.vo.WxBrandDataVO;
import com.cskaoyan.model.vo.WxBrandVO;
import com.cskaoyan.service.WxBrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @program: 微信小程序
 * @description:
 * @author: Wang
 * @create: 2022-05-09 17:29
 **/

@Repository
public class WxBrandServiceImpl implements WxBrandService {

    @Autowired
    BrandMapper brandMapper;

    /*
     * description 获取品牌商列表
     * @author Wangtianhao
     * @date 2022-05-09 20:07
     */
    @Override
    public WxBrandDataVO queryWxBrandList(BaseParamBO param){
        Integer page = param.getPage();//页码
        Integer limit = param.getLimit();//数据量
        String sort = param.getSort();//排序列
        String order = param.getOrder();//desc\asc
        //分页插件 PageHelper，辅助我们做分页以及分页信息的获得
        PageHelper.startPage(page, limit);
        //执行查询过程中拼接分页信息
        List<WxBrandVO> list = brandMapper.queryWxAddressList(param);

        //total、pages、list
        //通过PageHelper帮我们来获得一些和分页相关的信息PageInfo
        //使用其有参构造方法 → 形参写来源于数据库的list
        PageInfo<WxBrandVO> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        return WxBrandDataVO.data(total,pages,limit,page,list);
    }

    /*
     * description 获取品牌商信息
     * @author Wangtianhao
     * @date 2022-05-09 20:07
     */
    @Override
    public Brand queryWxBrandDetail(Integer id) {
        return brandMapper.selectByPrimaryKey(id);
    }

}
